package com.example.backend.service;

import com.example.backend.mapper.DingDanDetailMapper;
import com.example.backend.mapper.DingDanMapper;
import com.example.backend.mapper.ShopMapper;
import com.example.backend.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StatisticsService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Autowired
    private DingDanMapper dingDanMapper;

    @Autowired
    private DingDanDetailMapper dingDanDetailMapper;

    // 获取总用户数
    public int getUserCount() {
        return userMapper.countUsers();
    }

    // 获取总商家数
    public int getShopCount() {
        return shopMapper.countShops();
    }

   // 获取总订单数
    public int getOrderCount() {
        return dingDanMapper.countOrders();
    }

    // 获取已完成订单数
    public int getCompletedOrderCount() {
        return dingDanMapper.countCompletedOrders();
    }

    // 获取总销售额
    public double getTotalSales() {
        return dingDanDetailMapper.calculateTotalSales();
    }

    // 获取订单趋势数据
    public List<Map<String, Object>> getOrderTrend() {
        return dingDanMapper.getOrderTrend();
    }

    // 获取销售趋势数据
    public List<Map<String, Object>> getSalesTrend() {
        return dingDanDetailMapper.getSalesTrend();
    }
    
    // 获取商家地理分布数据
    public List<Map<String, Object>> getShopGeoDistribution() {
        return shopMapper.getShopGeoDistribution();
    }
    
    // 获取用户年龄分布数据
    public List<Map<String, Object>> getUserAgeDistribution() {
        return userMapper.getUserAgeDistribution();
    }
}